package com.example.xiaomi.controller;

import com.example.xiaomi.entity.contents;
import com.example.xiaomi.entity.hot;
import com.example.xiaomi.service.ContentsService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageInfo;
import java.util.List;

@RestController
@RequestMapping("contents")
@CrossOrigin  //允许跨域
public class ContentsController {
    @Autowired
    private ContentsService service;

    @GetMapping("pages")
    public PageInfo<contents> getPagesComment(Integer pageNum, Integer pageSize, String contents){
        PageInfo<contents> pageInfo = service.findContentsPages(pageNum,pageSize,contents);
        return pageInfo;
    }
    /**
     * http://localhost:8080/contents/list1    输出帖子相关信息：帖子内容，发帖人...
     */
    @GetMapping("/list1")
    public List<contents> getAllContents(){
        List<contents> infoList=service.findAllContents();
        return infoList;
    }

    /**
     * http://localhost:8080/contents/list2    输出帖子、转发、评论、点赞总数
     */
    @GetMapping("/list2")
    public List<contents> getContentsAccount(){
        List<contents> infoList = service.findContentsAccount();
        return infoList;
    }
    /**
     * http://localhost:8080/contents/get/1    根据帖子mid，输出对应帖子内容
     */
    @GetMapping("/get/{id}")
    public List<contents> getContentsById(@PathVariable("id") Integer mid){
        List<contents> info=service.findContentsById(mid);
        return info;
    }
    /**
     * 根据contents
     */
    @GetMapping("list3")
    public List<contents> findContentsByContents(String contents) {
        return service.findContentsByContents(contents);
    }
    /**
     *  http://localhost:8080/contents/list4            输出对应日期下的帖子数量
     */
    @GetMapping("/list4")
    public List<contents> findContentsByDate(){
        List<contents> ret = service.findContentsByDate();
        return ret;
    }
    /**
     * http://localhost:8080/contents/list5    输出分阶段的帖子内容主题分类
     */
    @GetMapping ("/list5")
    public List<contents> findContentsTopic(Integer stage_idx,Integer topic_idx){
        List<contents> info=service.findContentsTopic(stage_idx,topic_idx);
        return info;
    }
    @GetMapping ("/list6")
    public List<contents> findContentsTopic1(){
        List<contents> info=service.findContentsTopic1();
        return info;
    }

}
